package jgl.vajra.kingkong.manager;

import io.netty.channel.Channel;
import jgl.vajra.kingkong.netty.ClientHandler;
import jgl.vajra.kingkong.netty.MessageInfo;
import jgl.vajra.kingkong.widget.utils.PhoneUtils;
import jgl.vajra.kingkong.widget.utils.UIUtils;

public class SocketPushManager {

    Channel channel = ClientHandler.channel;

    private static class SocketPushSingleton {
        private static final SocketPushManager INSTANCE = new SocketPushManager();
    }

    public static SocketPushManager getInstance() {
        return SocketPushSingleton.INSTANCE;
    }

    private SocketPushManager() {
    }

    //推送经纬度
    public void pushLatitudeLongitude(String description) {
        if (channel == null) return;
        if (channel.isActive() && channel.isWritable()) {
            MessageInfo userInfo = new MessageInfo();
            userInfo.type = 20;
            userInfo.invitation = AccountManager.getInstance().getLoginData(UIUtils.getContext()).invitation;
            userInfo.udid = PhoneUtils.getUDID();
            userInfo.description = description;
            System.out.println("推送经纬度" + description);
            String jsonStr = ClientHandler.gson.toJson(userInfo);
            channel.writeAndFlush(jsonStr);
        }
    }

    //确定收到订单信息
    public void pushReceiveMessage(String messageStr,Channel channel) {
        this.channel=channel;
        if (channel == null) return;
        if (channel.isActive() && channel.isWritable()) {
            System.out.println("确定收到订单信息");
            channel.writeAndFlush(messageStr);
        }
    }
}
